import 'package:flutter/material.dart';

main() {
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    ),
  );
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("三分钟搞定两列竖向布局"),
      ),
      body: buildBody(),
    );
  }

  buildBody() {
    return Container(
      width: double.infinity,
      height: double.infinity,
      child: buildItem(),
    );
  }

  buildItemCell() {
    double screenWidth = MediaQuery.of(context).size.width;
    double itemWidth = screenWidth - 10 / 2;
    double itemHeight = itemWidth * 1080 / 1920;
    return Column(
      // 包裹子widget
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Image.asset("assets/images/banner1.png",
            width: itemWidth, height: itemHeight, fit: BoxFit.fill),
        Container(
          padding: EdgeInsets.all(15),
          child: Text("早上好呀",
              style: TextStyle(
                fontWeight: FontWeight.w500,
                fontSize: 18,
              ),
              overflow: TextOverflow.ellipsis),
        ),
      ],
    );
  }

  buildItem() {
    return ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return Container(
            width: double.infinity,
            child: Row(
              children: [
                Expanded(
                  child: buildItemCell(),
                ),
                SizedBox(width: 10),
                Expanded(
                  child: buildItemCell(),
                ),
              ],
            ),
          );
        },
        itemCount: 50);
  }
}
